home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_9.zip
/
7.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-27
|
37KB
|
1,159 lines
/*
* Copyright (C) 1985-1992 New York University
*
* This file is part of the Ada/Ed-C system. See the Ada/Ed README file for
* warranty (none) and distribution info and also the GNU General Public
* License for more details.
*/
#include "hdr.h"
#include "libhdr.h"
#include "vars.h"
#include "setp.h"
#include "errmsgp.h"
#include "dclmapp.h"
#include "libp.h"
#include "miscp.h"
#include "unitsp.h"
#include "nodesp.h"
#include "smiscp.h"
#include "chapp.h"
/* TBSL: check that check_priv_decl always called with first
argument (kind) as integer, corresponding to MISC_TYPE_ATTRIBUTE...
*/
static int in_relevant_scopes(int);
static Symbol trace_ancestor(Symbol, Tuple);
static void private_part(Node);
void package_specification(Node node) /*; package specification */
{
Node id_node, decl_node, priv_node;
id_node = N_AST1(node);
decl_node = N_AST2(node);
priv_node = N_AST3(node);
new_package(id_node, na_package_spec);
package_declarations(decl_node, priv_node);
end_specs(N_UNQ(id_node));
}
void new_package(Node id_node, int nat) /*;new_package*/
{
/* Process a package specification: install scope, initialize mappings. */
char *id;
Symbol ud;
int body_number;
if (cdebug2 > 3) TO_ERRFILE("AT PROC : new_package");
id = N_VAL(id_node);
new_compunit("sp", id_node);
if (nat==na_generic_part && IS_COMP_UNIT) {
/* allocate unit number for body, and mark it obsolete */
body_number = unit_number(strjoin("bo", id));
pUnits[body_number]->libInfo.obsolete = string_ds; /*"$D$"*/
}
newmod(id);
N_UNQ(id_node) = scope_name;
NATURE(scope_name) = nat;
TYPE_OF(scope_name) = symbol_none;
/* Create dummy entry to hold use clauses, which are declarative items.*/
find_new("$used");
/* use_declarations in SETL is signature(declared(scope_name), '$used') */
ud = dcl_get(DECLARED(scope_name), "$used");
SIGNATURE(ud) = tup_new(0);
private_decls(scope_name) = (Set) private_decls_new(0);
}
void package_declarations(Node decl_node, Node priv_node)
/*;package_declarations */
{
char *str;
Symbol s1, u_name;
Fordeclared dcliv;
adasem(decl_node);
/* The declarations so far constitute the visible part of the package*/
/* save current declarations */
/* visible(scope_name) = declared(scope_name); */
FORDECLARED(str, s1, DECLARED(scope_name), dcliv);
IS_VISIBLE(dcliv) = TRUE;
ENDFORDECLARED(dcliv);
FORDECLARED(str, u_name, DECLARED(scope_name), dcliv)
if (TYPE_OF(u_name) == symbol_incomplete) {
errmsg_id("missing full declaration for %", u_name, "3.8.1", decl_node);
}
ENDFORDECLARED(dcliv);
/* Now process private part of package.*/
private_part(priv_node);
}
void module_body_id(int mod_nature, Node name_node) /*;module_body_id*/
{
/* This procedure is invoked when the name of a module body has been
* seen. It opens the new scope, and if necessary retrieves from the
* library the specifications for the module.
*/
Symbol mod_name, c, real_t;
char *spec_name;
int nat, mattr, mark;
char *id;
Symbol s1, s2, t;
Fordeclared fd1;
Forprivate_decls fp1;
Private_declarations pd;
Tuple ud;
Symbol uds; /* check tupe of this ds 4 aug */
Fortup ft1;
if (cdebug2 > 3) TO_ERRFILE("AT PROC : module_body_id");
new_compunit("bo", name_node);
find_old(name_node);
mod_name = N_UNQ(name_node);
if (!IS_COMP_UNIT && SCOPE_OF(mod_name) != scope_name) {
errmsg("Specification and body are in different scopes" , "7.1, 9.1",
name_node);
}
/* Nature of specification must match that of current body*/
/*
* const specs_of = {
* [na_package, {na_package_spec, na_generic_package_spec}],
* [na_task_type, {na_task_type_spec, na_task_obj_spec}] };
* if (NATURE(mod_name) in specs_of(mod_nature) ) {
* rmatch(nature(mod_name), '_spec'); $ not a spec any longer
* }
*/
nat = NATURE(mod_name);
if (mod_nature == na_package
&& (nat == na_package_spec || nat == na_generic_package_spec)
|| (mod_nature == na_task_type && (nat == na_task_type_spec
|| nat == na_task_obj_spec
|| (nat == na_obj && NATURE(TYPE_OF(mod_name)) == na_task_type_spec)))) {
/* if the task appeared in a previously (separately) compiled unit,
* the expander has already changed its nature to na_obj
*/
if (nat == na_package_spec) nat = na_package;
else if (nat == na_generic_package_spec)
nat = na_generic_package;
else if (nat == na_task_type_spec)
nat = na_task_type;
else if (nat == na_task_obj_spec)
nat = na_task_obj;
else if (nat == na_obj)
NATURE(TYPE_OF(mod_name)) = na_task_type;
NATURE(mod_name) = nat;
}
else {
errmsg_nval("Matching specification not found for body %", name_node,
"7.1, 9.1", name_node);
}
/* if module is a generic package body and the current unit is a package
* body, verify that the generic spec appeared in the same file.
*/
if (NATURE(mod_name) == na_generic_package
&& streq(unit_name_type(unit_name), "bo")) {
if (is_subunit(unit_name))
spec_name = pUnits[stub_parent_get(unit_name)]->name;
else
spec_name = strjoin("sp", unit_name_name(unit_name));
if (!streq(lib_unit_get(spec_name), AISFILENAME))
errmsg("Separately compiled generics not supported", "none",
name_node);
}
newscope (mod_name); /* added to match SETL gcs 23 jan */
if (private_decls(mod_name) == (Set)0)
private_decls(mod_name) = (Set) private_decls_new(0);
/* For safe processing of body.*/
if (DECLARED(mod_name) == (Declaredmap)0)
DECLARED(mod_name) = dcl_new(0);
if (NATURE(mod_name) == na_task_type ) {
/* Within the body of a task type, the name of the task can be used
* to designate the task currently executing the body. We create an
* alias to be elaborated at run-time, under the name 'current_task'.
*/
c = find_new(strjoin("", "current_task"));
TYPE_OF(c) = mod_name;
NATURE(c) = na_obj;
}
else if (NATURE(mod_name) == na_task_obj ) {
/* remove -spec marker from its anonymous task type as well.*/
NATURE(TYPE_OF(mod_name)) = na_task_type;
}
else if (mod_nature == na_package ) {
/* Within a package body, declarations from the private part of the
* specification are visible. Swap visible and private versions.
*/
pd = (Private_declarations) private_decls(mod_name);
FORPRIVATE_DECLS(s1, s2, pd, fp1);
private_decls_swap(s1, s2);
ENDFORPRIVATE_DECLS(fp1);
/* (forall [item, pdecl] in private_decls(mod_name))
* [SYMBTABF(item), private_decls(mod_name)(item)] :=
* [pdecl, SYMBTABF(item)];
* end forall;
*/
/* Furthermore, composite types that depend on (outer) private types
* may now be fully useable if the latter received full declarations,
* (as long as they do not depend in external private types...)
*/
FORDECLARED(id, t, DECLARED(mod_name), fd1);
if (NATURE(t) == na_package_spec && !tup_mem((char *) t, vis_mods) )
vis_mods = tup_with(vis_mods, (char *) t);
else if (! is_type(t)) continue;
mattr = (int) misc_type_attributes(t);
mark = 0;
if (mattr & TA_PRIVATE)
mark = TA_PRIVATE;
else if (mattr & TA_LIMITED_PRIVATE)
mark = TA_LIMITED_PRIVATE;
/* exclude the mark 'limited' from this test (gs apr 1 85) */
/* else if (mattr & TA_LIMITED)
* mark = TA_LIMITED;
*/
else if (mattr & TA_INCOMPLETE)
mark = TA_INCOMPLETE;
if (mark == 0) continue;
if (is_access(t)) real_t = (Symbol) designated_type(t);
else real_t = t;
if (!is_private(real_t) ) {
/* full declaration of private ancestor(s) has been seen.
* save visible declaration before updating.
*/
private_decls_put((Private_declarations)
private_decls(mod_name), t);
misc_type_attributes(t) = (misc_type_attributes(t) & ~mark );
}
ENDFORDECLARED(fd1);
/* and install the use clauses that were encountered in the
* specification.
*/
uds = dcl_get(DECLARED(mod_name), "$used");
if ( uds != (Symbol)0 ) {
ud = SIGNATURE(uds);
FORTUP(uds=(Symbol), ud, ft1);
used_mods = tup_with(used_mods, (char *) uds);
ENDFORTUP(ft1);
}
/* Else the body was not found. Error was emitted already.*/
}
/* Initialize the stacks used for label processing.*/
lab_init();
}
void module_body(int nat, Node block